from django.utils.deprecation import MiddlewareMixin
from user.models import UserModel
from django.http import HttpResponseRedirect


# 中间件，检测用户是否登录
class IsLoginMidd(MiddlewareMixin):
    def process_request(self, request):
        uid = request.headers.get('Authorization')
        print('midd get uid-----')
        print(uid)

        if not uid:
            request.is_login = False
        try:
            UserModel.objects.get(pk=uid)
            request.is_login = True
        except Exception:
            request.is_login = False